package wsepForum.common.elements;

import java.util.Random;
import java.util.Vector;

/**
 *
 * @author Ofir Tam & Ori Ossmy
 *
 */
public class User {


	/*****************************
	 * MEMBERS                   *
	 *****************************/
	/**
	 *
	 */
	public static enum UserType {MEMBER, MODERATOR, ADMIN, GUEST };

	/**
	 *
	 */
	private String userName;

	/**
	 *
	 */
	private String password;

	/**
	 *
	 */
	private UserType userType;

	/**
	 *
	 */
	private Vector<Integer> sections;

	/**
	 *
	 */
	private int personalSalt;



	/*****************************
	 * CONSTRUCTOR               *
	 *****************************/
	/**
	 *
	 * @param userName
	 * @param password
	 * @param userType
	 */
	public User(String userName, String password, UserType userType) {
		this.userName = userName;
		this.password = password;
		this.userType = userType;
		this.sections = new Vector<Integer>();
		this.personalSalt = (new Random()).nextInt(Integer.MAX_VALUE);
	}



	/*****************************
	 * METHODS                   *
	 *****************************/
	/**
	 *
	 * @return
	 */
	public String getUserName() {
		return this.userName;
	}

	/**
	 *
	 * @return
	 */
	public String getPassword() {
		return this.password;
	}

	/**
	 *
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 *
	 * @return
	 */
	public UserType getUserType() {
		return this.userType;
	}

	/**
	 *
	 * @param password
	 */
	public void setUserType(UserType userType) {
		this.userType = userType;
	}

	/**
	 *
	 * @param section
	 */
	public void addSection(int section) {
		this.sections.add(section);
	}

	/**
	 *
	 * @param section
	 */
	public void removeSection(int section) {
		this.sections.removeElement((Integer)section);
	}

	/**
	 *
	 * @param section
	 * @return
	 */
	public boolean hasSection(int section) {
		return this.sections.contains((Integer)section);
	}

	/**
	 *
	 * @return
	 */
	public Vector<Integer> getAllSections() {
		return this.sections;
	}


	/**
	 *
	 * @return
	 */
	public Integer getUserSalt(){
		return this.personalSalt;
	}
	
	
	public void setSalt(int salt){
		this.personalSalt = salt;
		
	}




	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof User))
			return false;
		final User other = (User) obj;
		if (userName == null) {
			if (other.userName != null)
				return false;
		} else if (!userName.equals(other.userName))
			return false;
		if (userType == null) {
			if (other.userType != null)
				return false;
		} else if (!userType.equals(other.userType))
			return false;
		return true;
	}



}
